package com.sikao.app.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.sikao.app.R;
import com.sikao.app.adapter.PicturesAdapter;
import com.sikao.app.adapter.SellerOrderExtraInfoAdapter;
import com.sikao.app.bean.Bean;
import com.sikao.app.bean.BuyerOrderDetailBean;
import com.sikao.app.bean.GetOrderDetailSubmitBean;
import com.sikao.app.bean.SellerOrderDetailBean;
import com.sikao.app.bean.SellerOrderOperateSubmitBean;
import com.sikao.app.dao.SellerOrderDetailModel;
import com.sikao.app.dao.SellerOrderOperateModel;
import com.sikao.app.myinterface.Callback;
import com.sikao.app.net.HttpApi;
import com.sikao.app.net.OnNetBackListener;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.EditTextUtils;
import com.sikao.app.utils.JSONUtil;
import com.sikao.app.utils.SizeConvertUtils;
import com.sikao.app.utils.TimeUtil;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import static com.sikao.app.R.id.btn_second_money;

public class SellerOrderDetailActivity extends BaseActivity implements View.OnClickListener {

	private TextView titleTv;
	private TextView scheduleTv;
	private ImageView backIv;
	private TextView tvOrderNumber;
	private TextView tvStatus;
	private TextView tvName;
	private TextView tvPhone;
	private TextView tvCompanyName;
	private Button btnSendMail;
	private TextView tvGoodsType;
	private TextView tvGoodsName;
	private TextView tvQuantity;
	private TextView tvQuantityUnit;
	private TextView tvPrice;
	private TextView tvPriceUnit;
	private TextView tvAllPrice;
	private TextView tvReleaseType;
	private TextView tvPayType;
	private TextView tvPayMode;
	private LinearLayout llWarehouseReceipt;
	private GridView gridViewWarehouseReceipt;//仓单图片
	private TextView tvDeliveryMode;
	private TextView tvStartDate;
	private TextView tvDeliveryPlace;
	private GridView gridViewExtraInf;//附加信息
	private LinearLayout llInspectionReport;
	private GridView gridViewInspectionReport;//验收报告
	private LinearLayout llAcceptanceReport;
	private TextView tvGoodsWeight;
	private TextView tvCarriagePrice;
	private TextView tvFinalTotalPrice;
	private GridView gridViewAcceptanceReport;//检验报告
	private Button btnChangePrice;
	private Button btnCancelOrder;
	private Button btnConfirmOrder;
	private Button btnFirstMoney;
	private Button btnApplyArbitration;
	private Button btnWaitArbitration;
	private Button btnViewArbitration;
	private Button btnCompleteStock;
	private Button btnSecondMoney;
	private Button btnRefuseReport;
	private Button btnConfirmReport;
	private Button btnHasRefusedReport;
	private Button btnThreeMoney;
	private Button btnViewEvaluation;

	private int schedule;//订单进度 1、确认订单，2、等待对方付首款，3、进行备货，4、等待对方付尾款，5.等待对方提交验收报告，6、等待对方验收发票，7、等待对方付尾款，8、等待对方评价，9、已完成
	private int status;//1、确认订单，2、等待对方付首款，3、进行备货，4、等待对方付尾款，5.等待对方提交验收报告，6、对方已提交验收报告，7、拒绝了验收报告，8、等待对方验收发票，9、等待对方付尾款，10、等待对方评价，11、已完成 12、取消了订单 13、申请了仲裁（仲裁中） 14、平台仲裁结束
	private SellerOrderDetailModel sellerOrderDetailModel;
	private GetOrderDetailSubmitBean getOrderDetailSubmitBean;
	private PicturesAdapter warehouseReceiptAdapter, inspectionReportAdapter, acceptanceReportAdapter;
	private SellerOrderExtraInfoAdapter sellerOrderExtraInfoAdapter;

	private List<String> warehouseReceiptList, inspectionReportList, acceptanceReportList;

	private SellerOrderOperateModel sellerOrderOperateModel;//订单处理model
	private SellerOrderOperateSubmitBean orderOperateSubmitBean;
	private SellerOrderDetailBean bean;

	private DecimalFormat format2 = new DecimalFormat("0.00");

	private String beanId;
	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_seller_order_detail);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		beanId = getIntent().getStringExtra("bean");
		intent = new Intent();
		orderOperateSubmitBean = new SellerOrderOperateSubmitBean();

	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		scheduleTv = (TextView) findViewById(R.id.title_right_tv);
		tvOrderNumber = (TextView) findViewById(R.id.tv_order_number);
		tvStatus = (TextView) findViewById(R.id.tv_status);
		tvName = (TextView) findViewById(R.id.tv_name);
		tvPhone = (TextView) findViewById(R.id.tv_phone);
		tvCompanyName = (TextView) findViewById(R.id.tv_company_name);
		btnSendMail = (Button) findViewById(R.id.btn_send_mail);
		tvGoodsType = (TextView) findViewById(R.id.tv_goods_type);
		tvGoodsName = (TextView) findViewById(R.id.tv_goods_name);
		tvQuantity = (TextView) findViewById(R.id.tv_quantity);
		tvQuantityUnit = (TextView) findViewById(R.id.tv_quantity_unit);
		tvPrice = (TextView) findViewById(R.id.tv_price);
		tvPriceUnit = (TextView) findViewById(R.id.tv_price_unit);
		tvAllPrice = (TextView) findViewById(R.id.tv_all_price);
		tvReleaseType = (TextView) findViewById(R.id.tv_release_type);
		tvPayType = (TextView) findViewById(R.id.tv_pay_type);
		tvPayMode = (TextView) findViewById(R.id.tv_pay_mode);
		llWarehouseReceipt = (LinearLayout) findViewById(R.id.ll_warehouse_receipt);
		gridViewWarehouseReceipt = (GridView) findViewById(R.id.gridView_warehouse_receipt);
		tvDeliveryMode = (TextView) findViewById(R.id.tv_delivery_mode);
		tvDeliveryPlace = (TextView) findViewById(R.id.tv_delivery_place);
		tvStartDate = (TextView) findViewById(R.id.tv_start_date);
		gridViewExtraInf = (GridView) findViewById(R.id.gridView_extra_inf);
		llInspectionReport = (LinearLayout) findViewById(R.id.ll_inspection_report);
		gridViewInspectionReport = (GridView) findViewById(R.id.gridView_inspection_report);
		llAcceptanceReport = (LinearLayout) findViewById(R.id.ll_acceptance_report);
		tvGoodsWeight = (TextView) findViewById(R.id.tv_goods_weight);
		tvCarriagePrice = (TextView) findViewById(R.id.tv_carriage_price);
		tvFinalTotalPrice = (TextView) findViewById(R.id.tv_final_total_price);
		gridViewAcceptanceReport = (GridView) findViewById(R.id.gridView_acceptance_report);
		btnChangePrice = (Button) findViewById(R.id.btn_change_price);
		btnCancelOrder = (Button) findViewById(R.id.btn_cancel_order);
		btnConfirmOrder = (Button) findViewById(R.id.btn_confirm_order);
		btnFirstMoney = (Button) findViewById(R.id.btn_first_money);
		btnApplyArbitration = (Button) findViewById(R.id.btn_apply_arbitration);
		btnWaitArbitration = (Button) findViewById(R.id.btn_wait_arbitration);
		btnViewArbitration = (Button) findViewById(R.id.btn_view_arbitration);
		btnCompleteStock = (Button) findViewById(R.id.btn_complete_stock);
		btnSecondMoney = (Button) findViewById(btn_second_money);
		btnRefuseReport = (Button) findViewById(R.id.btn_refuse_report);
		btnConfirmReport = (Button) findViewById(R.id.btn_confirm_report);
		btnHasRefusedReport = (Button) findViewById(R.id.btn_has_refused_report);
		btnThreeMoney = (Button) findViewById(R.id.btn_three_money);
		btnViewEvaluation = (Button) findViewById(R.id.btn_view_evaluation);

	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		scheduleTv.setOnClickListener(this);
		btnSendMail.setOnClickListener(this);
		btnChangePrice.setOnClickListener(this);
		btnCancelOrder.setOnClickListener(this);
		btnConfirmOrder.setOnClickListener(this);
		btnFirstMoney.setOnClickListener(this);
		btnApplyArbitration.setOnClickListener(this);
		btnViewArbitration.setOnClickListener(this);
		btnCompleteStock.setOnClickListener(this);
		btnSecondMoney.setOnClickListener(this);
		btnRefuseReport.setOnClickListener(this);
		btnConfirmReport.setOnClickListener(this);
		btnThreeMoney.setOnClickListener(this);
		btnViewEvaluation.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("订单详情");
		backIv.setVisibility(View.VISIBLE);
		scheduleTv.setText("进度");
		scheduleTv.setVisibility(View.VISIBLE);
		getOrderDetail(true);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				setResult(RESULT_OK, getIntent());
				finish();
				break;
			case R.id.btn_send_mail:
				if (bean == null) {
					return;
				}
				intent.setClass(SellerOrderDetailActivity.this, SendMailActivity.class);
				intent.putExtra("type", "name");
				intent.putExtra("value", bean.getRes().getUser_info().getNickname());
				startActivity(intent);
				break;
			case R.id.btn_change_price:
				changePrice();
				break;
			case R.id.btn_cancel_order:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("cancel");
					}
				});
				break;
			case R.id.btn_confirm_order:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("doConfirm");
					}
				});
				break;
			case R.id.btn_first_money:
				payMoney(1);
				break;
			case R.id.btn_apply_arbitration:
				if (bean == null) {
					return;
				}
				intent.setClass(SellerOrderDetailActivity.this, ArbitrateActivity.class);
				intent.putExtra("type", "seller");
				intent.putExtra("bean", bean.getRes().getId());
				startActivityForResult(intent, 1);
				break;
			case R.id.btn_view_arbitration:
				if (bean == null) {
					return;
				}
				intent.setClass(SellerOrderDetailActivity.this, ArbitrationResultActivity.class);
				intent.putExtra("type", "seller");
				intent.putExtra("bean", bean.getRes().getId());
				startActivity(intent);
				break;
			case R.id.btn_complete_stock:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("goodsOk");
					}
				});
				break;
			case R.id.btn_second_money:
				payMoney(2);
				break;
			case R.id.btn_refuse_report:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("refuse");
					}
				});
				break;
			case R.id.btn_confirm_report:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("confirm");
					}
				});
				break;
			case R.id.btn_three_money:
				payMoney(3);
				break;
			case R.id.btn_view_evaluation:
				if (bean == null) {
					return;
				}
				intent.setClass(SellerOrderDetailActivity.this, EvaluationActivity.class);
				intent.putExtra("type", "seller");
				intent.putExtra("bean", bean.getRes().getId());
				startActivity(intent);
				break;
			case R.id.title_right_tv:
				if (bean == null) {
					return;
				}
				intent.setClass(SellerOrderDetailActivity.this, SellerOrderScheduleActivity.class);
				if (bean.getRes().getStatus().equals("7") && bean.getRes().getIs_comment().equals("1")) {
					intent.putExtra("schedule", 8);
				} else {
					intent.putExtra("schedule", Integer.parseInt(bean.getRes().getStatus()));
				}
				startActivity(intent);
				break;
			default:
				break;
		}
	}

	@Override
	public void onBackPressed() {
		setResult(RESULT_OK, getIntent());
		super.onBackPressed();
	}

	/**
	 * 确定线下付款
	 */

	private void payMoney(final int step) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		View view = View.inflate(this, R.layout.seller_order_offline_payment_dialog, null);//线下付款
		builder.setView(view);
		final Dialog dialog = builder.create();
		TextView tvPayStep = (TextView) view.findViewById(R.id.tv_pay_step);
		TextView tvMoney = (TextView) view.findViewById(R.id.tv_money);
		Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);
		Button btnConfirm = (Button) view.findViewById(R.id.btn_confirm);
		if (step == 1) {
			tvPayStep.setText("买家线下首款");
			tvMoney.setText(bean.getRes().getThis_pay().getPayMoney());
		}
		if (step == 2) {
			tvPayStep.setText("买家线下中期款");
			tvMoney.setText(bean.getRes().getThis_pay().getPayMoney());
		}
		if (step == 3) {
			tvPayStep.setText("买家线下尾款");
			tvMoney.setText(bean.getRes().getThis_pay().getPayMoney());
		}
		btnCancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		btnConfirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (step == 1) {
					orderOperate("confirmPayOne");
				}
				if (step == 2) {
					orderOperate("confirmPayTwo");
				}
				if (step == 3) {
					orderOperate("confirmPayThree");
				}
				dialog.dismiss();
			}
		});
		dialog.show();
		dialog.setCanceledOnTouchOutside(false);
		dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		Window dialogWindow = dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = SizeConvertUtils.dip2px(260);
		dialogWindow.setAttributes(lp);
		dialog.setCanceledOnTouchOutside(false);
	}

	/**
	 * 修改价格
	 */
	private void changePrice() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		View view = View.inflate(this, R.layout.change_price_dialog, null);
		builder.setView(view);
		final Dialog dialog = builder.create();
		TextView textView = (TextView) view.findViewById(R.id.tv_now_price);
		textView.setText(bean.getRes().getTotal_price());
		final EditText editText = (EditText) view.findViewById(R.id.et_price);
		EditTextUtils.setPricePoint(2, editText);
		Button cancle = (Button) view.findViewById(R.id.btn_cancel);
		Button confirm = (Button) view.findViewById(R.id.btn_confirm);
		cancle.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		confirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (editText.getText().toString().length() == 0) {
					Toast.makeText(SellerOrderDetailActivity.this, "请输入修改的价格", Toast.LENGTH_SHORT).show();
				}
				orderOperateSubmitBean.setTotalPrice(format2.format(Double.valueOf(editText.getText().toString())));
				orderOperate("changePrice");
				dialog.dismiss();
			}
		});
		dialog.show();
		dialog.setCanceledOnTouchOutside(false);
		dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		Window dialogWindow = dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = SizeConvertUtils.dip2px(260);
		dialogWindow.setAttributes(lp);
		dialog.setCanceledOnTouchOutside(false);

	}

	/**
	 * 获取订单详情
	 *
	 * @param isShow 是否显示加载动画
	 */
	private void getOrderDetail(boolean isShow) {
		if (sellerOrderDetailModel == null) {
			sellerOrderDetailModel = new SellerOrderDetailModel(this, new OnNetBackListener<SellerOrderDetailBean>() {
				@Override
				public void netBack(SellerOrderDetailBean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")) {
						bean = data;
						showContent();
					} else {
						Toast.makeText(SellerOrderDetailActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
		}
		getOrderDetailSubmitBean = new GetOrderDetailSubmitBean();
		getOrderDetailSubmitBean.setOrderId(beanId);
		sellerOrderDetailModel.request(JSONUtil.toJSON(getOrderDetailSubmitBean), isShow);
	}

	private void showContent() {
		tvOrderNumber.setText(bean.getRes().getId());
		tvName.setText(bean.getRes().getUser_info().getNickname());
		tvPhone.setText(bean.getRes().getUser_info().getMobile());
		tvCompanyName.setText(bean.getRes().getUser_info().getCom_name());
		tvGoodsType.setText(bean.getRes().getGoods_info().getCat_name());
		tvGoodsName.setText(bean.getRes().getGoods_info().getTitle());
		tvQuantity.setText(bean.getRes().getNumber());
		tvQuantityUnit.setText(bean.getRes().getGoods_info().getUnit());
		tvPrice.setText(bean.getRes().getPrice());
		tvPriceUnit.setText(bean.getRes().getGoods_info().getUnit());
		tvAllPrice.setText(bean.getRes().getTotal_price());
		tvReleaseType.setText(bean.getRes().getGoods_info().getPublish_type_str());
		tvPayType.setText(bean.getRes().getGoods_info().getPay_method_str());
		tvPayMode.setText(bean.getRes().getGoods_info().getPay_type_str());
		if (bean.getRes().getGoods_info().getPublish_type().equals("1")) {
			llWarehouseReceipt.setVisibility(View.VISIBLE);
			warehouseReceiptList = new ArrayList<>();
			List<SellerOrderDetailBean.ResBean.GoodsInfoBean.StorePicInfoBean> picBeans = bean.getRes().getGoods_info().getStore_pic_info();
			for (int i = 0; picBeans != null && i < picBeans.size(); i++) {
				warehouseReceiptList.add(HttpApi.BANNERUTL + picBeans.get(i).getUrl());
			}
			warehouseReceiptAdapter = new PicturesAdapter(this, warehouseReceiptList);
			gridViewWarehouseReceipt.setAdapter(warehouseReceiptAdapter);
		}
		tvStartDate.setText(TimeUtil.timeStampToTime(bean.getRes().getAdd_time(), "yyyy-MM-dd"));
		tvDeliveryMode.setText(bean.getRes().getGoods_info().getDelivery_type_str());
		tvDeliveryPlace.setText(bean.getRes().getGoods_info().getDelivery_area());
		/*if (bean.getRes().getOriginal_data() != null && bean.getRes().getOriginal_data().getAttr() != null) {
			sellerOrderExtraInfoAdapter = new SellerOrderExtraInfoAdapter(this, bean.getRes().getOriginal_data().getAttr());
			gridViewExtraInf.setAdapter(sellerOrderExtraInfoAdapter);//附加信息

		}*/

		List<SellerOrderDetailBean.ResBean.GoodsInfoBean.CheckReportInfoBean> reportList = bean.getRes().getGoods_info().getCheck_report_info();
		if (reportList != null && reportList.size() != 0) {
			inspectionReportList = new ArrayList<>();
			for (int i = 0; i < reportList.size(); i++) {
				inspectionReportList.add(HttpApi.BANNERUTL + reportList.get(i).getUrl());
			}
			inspectionReportAdapter = new PicturesAdapter(this, inspectionReportList);
			gridViewInspectionReport.setAdapter(inspectionReportAdapter);
		}
		dismissAllBtn();
		//验收提货状态 0默认初始值 1买家已提交 2卖家同意 3卖家不同意
		if (bean.getRes().getCheck_report_status() != null && !bean.getRes().getCheck_report_status().equals("0")) {
			llAcceptanceReport.setVisibility(View.VISIBLE);
			tvGoodsWeight.setText(bean.getRes().getCheck_report().getFinal_number());
			tvCarriagePrice.setText(bean.getRes().getCheck_report().getFreight());
			tvFinalTotalPrice.setText(bean.getRes().getCheck_report().getFinal_price());
			if (bean.getRes().getCheck_report().getFile_paths() != null) {
				acceptanceReportList = new ArrayList<>();
				for (int i = 0; i < bean.getRes().getCheck_report().getFile_paths().size(); i++) {
					acceptanceReportList.add(HttpApi.BANNERUTL + bean.getRes().getCheck_report().getFile_paths().get(i));
				}
				acceptanceReportAdapter = new PicturesAdapter(this, acceptanceReportList);
				gridViewAcceptanceReport.setAdapter(acceptanceReportAdapter);
			}
		}
		if (!bean.getRes().getException_status().equals("0")) {
			//取消
			if (bean.getRes().getException_status().equals("1")) {
				tvStatus.setText("订单已取消");
			}
			//过期
			if (bean.getRes().getException_status().equals("2")) {
				tvStatus.setText("订单已过期");
			}
			//冻结
			if (bean.getRes().getException_status().equals("3")) {
				tvStatus.setText("订单冻结中");
			}
			//仲裁中
			if (bean.getRes().getException_status().equals("4") && bean.getRes().getIs_end().equals("0")) {
				btnWaitArbitration.setVisibility(View.VISIBLE);
			}
			//仲裁后
			if (bean.getRes().getException_status().equals("4") && bean.getRes().getIs_end().equals("1")) {
				btnViewArbitration.setVisibility(View.VISIBLE);
			}
		} else {
			switch (bean.getRes().getStatus()) {
				case "0":
					btnCancelOrder.setVisibility(View.VISIBLE);
					btnConfirmOrder.setVisibility(View.VISIBLE);
					btnChangePrice.setVisibility(View.VISIBLE);
					tvStatus.setText("等待确认订单");
					break;
				case "1":
					if (!bean.getRes().getPay_type().equals("onLinePay") && bean.getRes().getPay_status().equals("1")) {
						tvStatus.setText("确定买家首款");
						btnApplyArbitration.setVisibility(View.VISIBLE);
						btnFirstMoney.setVisibility(View.VISIBLE);
					} else {
						tvStatus.setText("等待买家付首款");
					}
					break;
				case "2":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("进行备货");
					btnCompleteStock.setVisibility(View.VISIBLE);
					break;
				case "3":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					if (!bean.getRes().getPay_type().equals("onLinePay") && bean.getRes().getPay_status().equals("2")) {
						tvStatus.setText("确定买家中期款");
						btnSecondMoney.setVisibility(View.VISIBLE);
					} else {
						tvStatus.setText("等待买家付中期款");
					}
					break;
				case "4":
					//验收提货状态 0默认初始值 1买家已提交 2卖家同意 3卖家不同意
					btnApplyArbitration.setVisibility(View.VISIBLE);
					if (bean.getRes().getCheck_report_status().equals("0")) {
						tvStatus.setText("等待买家提交验收报告");
					}
					if (bean.getRes().getCheck_report_status().equals("1")) {
						tvStatus.setText("买家已提交验收报告");
						btnConfirmReport.setVisibility(View.VISIBLE);
						btnRefuseReport.setVisibility(View.VISIBLE);
					}
					if (bean.getRes().getCheck_report_status().equals("2")) {
						tvStatus.setText("已接受买家验收报告");
					}
					if (bean.getRes().getCheck_report_status().equals("3")) {
						tvStatus.setText("已拒绝验收报告,等待买家再次编辑");
						btnHasRefusedReport.setVisibility(View.VISIBLE);
					}
					break;
				case "5":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("等待买家验收发票");
					break;
				case "6":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					if (!bean.getRes().getPay_type().equals("onLinePay") && bean.getRes().getPay_status().equals("3")) {
						tvStatus.setText("确定买家尾款");
						btnSecondMoney.setVisibility(View.VISIBLE);
					} else {
						tvStatus.setText("等待买家付尾款");
					}
					break;
				case "7":
					if (!bean.getRes().getIs_comment().equals("1")) {
						tvStatus.setText("等待买家评价");
					} else {
						btnViewEvaluation.setVisibility(View.VISIBLE);
						tvStatus.setText("已结束");
					}
					break;
				default:
					break;
			}
		}
	}

	private void dismissAllBtn() {
		btnChangePrice.setVisibility(View.GONE);
		btnCancelOrder.setVisibility(View.GONE);
		btnConfirmOrder.setVisibility(View.GONE);
		btnFirstMoney.setVisibility(View.GONE);
		btnApplyArbitration.setVisibility(View.GONE);
		btnWaitArbitration.setVisibility(View.GONE);
		btnViewArbitration.setVisibility(View.GONE);
		btnCompleteStock.setVisibility(View.GONE);
		btnSecondMoney.setVisibility(View.GONE);
		btnRefuseReport.setVisibility(View.GONE);
		btnConfirmReport.setVisibility(View.GONE);
		btnHasRefusedReport.setVisibility(View.GONE);
		btnThreeMoney.setVisibility(View.GONE);
		btnViewEvaluation.setVisibility(View.GONE);
	}

	/**
	 * 订单操作
	 */
	private void orderOperate(String operate) {
		if (bean == null) {
			return;
		}
		if (sellerOrderOperateModel == null) {
			sellerOrderOperateModel = new SellerOrderOperateModel(this, new OnNetBackListener<Bean>() {
				@Override
				public void netBack(Bean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")) {
						getOrderDetail(true);
					} else {
						Toast.makeText(SellerOrderDetailActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
		}
		orderOperateSubmitBean.setOrderId(beanId);
		orderOperateSubmitBean.setAction(operate);
		sellerOrderOperateModel.request(JSONUtil.toJSON(orderOperateSubmitBean), true);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
				case 1://仲裁
					getOrderDetail(true);
					break;
				default:
					break;
			}
		}
	}

	private void showDialog(final Callback callback) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("确定执行此操作吗?");
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				callback.notice(1);
			}
		});
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}

}
